package com.thxy.jxgl.mubiaoka.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.thxy.jxgl.filter.ToCh;
import com.thxy.jxgl.javaBean.biaoxian;
import com.thxy.jxgl.javaBean.khjsff;
import com.thxy.jxgl.mubiaoka.manager.BiaoxianManager;
import com.thxy.jxgl.mubiaoka.manager.JsffManager;

/**
 * Servlet implementation class BiaoxianServlet
 */
public class BiaoxianServlet extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getParameter("method") == null?"":request.getParameter("method");
		request.setCharacterEncoding("gbk");
        if("addbiaoxian".equals(method))
        {
            String bx_id=request.getParameter("bx_id");
            String bx_yaosu=request.getParameter("bx_yaosu");
            String bx_yaodian=request.getParameter("bx_yaodian");
            String bx_zhouqi=request.getParameter("bx_zhouqi");
            String bx_quanzhong=request.getParameter("bx_quanzhong");
            String bx_ziping=request.getParameter("bx_ziping");
            String bx_shangji=request.getParameter("bx_shangji");
            String bx_xiaozu=request.getParameter("bx_xiaozu");
            biaoxian bx=new biaoxian();
            if(bx_quanzhong!=""){
            	bx.setBx_quanzhong(Float.parseFloat(bx_quanzhong));
            }
            if(bx_ziping!=""){
            	bx.setBx_ziping(Float.parseFloat(bx_ziping));
            }
            if(bx_shangji!=""){
            	bx.setBx_shangji(Float.parseFloat(bx_shangji));
            }
            if(bx_xiaozu!=""){
            	bx.setBx_xiaozu(Float.parseFloat(bx_xiaozu));
            }
            bx.setBx_id(bx_id);
            bx.setBx_yaosu(bx_yaosu);
            bx.setBx_yaodian(bx_yaodian);
            bx.setBx_zhouqi(bx_zhouqi);
            boolean ins=BiaoxianManager.getInstance().addBiaoxian(bx);
        }else if ("delebiaoxian".equals(method)) {
			String no=request.getParameter("bxno");
			BiaoxianManager.getInstance().deleBiaoxian(no);
		}
		else if ("editbiaoxian".equals(method)) {
			String bxno=request.getParameter("bxno");
            String bx_yaosu=request.getParameter("bx_yaosu");
            String bx_yaodian=request.getParameter("bx_yaodian");
            String bx_zhouqi=request.getParameter("bx_zhouqi");
            String bx_quanzhong=request.getParameter("bx_quanzhong");
            String bx_ziping=request.getParameter("bx_ziping");
            String bx_shangji=request.getParameter("bx_shangji");
            String bx_xiaozu=request.getParameter("bx_xiaozu");
            biaoxian bx=new biaoxian();
            if(bx_quanzhong!=""){
            	bx.setBx_quanzhong(Float.parseFloat(bx_quanzhong));
            }
            if(bx_ziping!=""){
            	bx.setBx_ziping(Float.parseFloat(bx_ziping));
            }
            if(bx_shangji!=""){
            	bx.setBx_shangji(Float.parseFloat(bx_shangji));
            }
            if(bx_xiaozu!=""){
            	bx.setBx_xiaozu(Float.parseFloat(bx_xiaozu));
            }
            bx.setBx_id(bxno);
            bx.setBx_yaosu(bx_yaosu);
            bx.setBx_yaodian(bx_yaodian);
            bx.setBx_zhouqi(bx_zhouqi);
			boolean upd=BiaoxianManager.getInstance().updateBiaoxian(bx);
		}
		List bxList=new ArrayList();
		bxList=BiaoxianManager.getInstance().getBiaoxian();
		request.getSession().setAttribute("bxList", bxList);
		request.getRequestDispatcher("/mbkgl/biaoxian.jsp").forward(request, response);

		}
	
}
